package com.ruoyi.project.member.controller;

import cn.mabach.member.entity.MemberEntity;
import cn.mabach.result.PageResult;
import cn.mabach.result.RS;
import cn.mabach.result.TableDataInfo;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;

import com.ruoyi.project.member.feign.MemberServiceFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 会员表
 *
 * @author chenshun
 * @email 176468159@qq.com
 * @date 2020-01-04 15:47:34
 */
@RestController
@RequestMapping("/member/member")
public class MemberController extends BaseController {
    @Autowired
    private MemberServiceFeign memberService;



    /**
        * 分页列表
        */
    @GetMapping(value = "/list")
    @PreAuthorize("@ss.hasPermi('member:member:read')")
    public TableDataInfo getList(@RequestParam(value = "username", required = false) String username,
                                 @RequestParam(value = "phone", required = false) String phone,
                                 @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {

        return memberService.queryPage(username, phone, pageNum, pageSize);


    }



    /**
     * 根据ID获取信息
     */

    @GetMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPermi('member:member:read')")
    public RS<MemberEntity> getItem(@PathVariable("id") Long id) {
        return memberService.getByIdE(id);
    }





    /**
     * 根据id保存
     */
    @PostMapping
    @PreAuthorize("@ss.hasPermi('member:member:create')")
    @Log(title = "会员", businessType = BusinessType.INSERT)
    public RS create(@RequestBody MemberEntity memberEntity) {

        RS rs = memberService.saveE(memberEntity);

        return rs;
    }



    /**
     * 根据id修改
     */
    @PutMapping
    @PreAuthorize("@ss.hasPermi('member:member:update')")
    @Log(title = "会员", businessType = BusinessType.UPDATE)
    public RS update(@RequestBody MemberEntity memberEntity) {

        RS rs = memberService.updateByIdE(memberEntity);

        return rs;
    }

    /**
       * 根据id集合删除
       */
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPermi('member:member:delete')")
    @Log(title = "会员", businessType = BusinessType.DELETE)
    public RS deleteBatch(@PathVariable Long[] ids) {
       ;
        RS rs = memberService.removeByIdsE(Arrays.asList(ids));
        return rs;
    }




}
